package org.fireflow2.designer.eclipse.parts;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.fireflow2.designer.eclipse.modelwrapper.SubProcessWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.ActivityWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.EndNodeWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.GroupWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.LaneWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.PoolWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.RouterWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.StartNodeWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.TransitionWrapper;
import org.fireflow2.designer.eclipse.parts.basic.BasicGroupPart;
import org.fireflow2.designer.eclipse.parts.basic.BasicLanePart;
import org.fireflow2.designer.eclipse.parts.basic.BasicPoolPart;
import org.fireflow2.designer.eclipse.parts.basic.BasicSubProcessPart;
import org.fireflow2.designer.eclipse.parts.designer.ActivityPart4Designer;
import org.fireflow2.designer.eclipse.parts.designer.EndNodePart4Designer;
import org.fireflow2.designer.eclipse.parts.designer.GroupPart4Designer;
import org.fireflow2.designer.eclipse.parts.designer.LanePart4Designer;
import org.fireflow2.designer.eclipse.parts.designer.PoolPart4Designer;
import org.fireflow2.designer.eclipse.parts.designer.RouterPart4Designer;
import org.fireflow2.designer.eclipse.parts.designer.StartNodePart4Designer;
import org.fireflow2.designer.eclipse.parts.designer.SubProcessPart4Designer;
import org.fireflow2.designer.eclipse.parts.designer.TransitionPart4Designer;
import org.fireflow2.designer.eclipse.parts.simulator.ActivityPart4Simulator;
import org.fireflow2.designer.eclipse.parts.simulator.EndNodePart4Simulator;
import org.fireflow2.designer.eclipse.parts.simulator.RouterPart4Simulator;
import org.fireflow2.designer.eclipse.parts.simulator.StartNodePart4Simulator;
import org.fireflow2.designer.eclipse.parts.simulator.TransitionPart4Simulator;

public class PartFactory implements EditPartFactory {
	private boolean editable = false;
	public PartFactory(boolean editable){
		this.editable = editable;
	}
	
	public EditPart createEditPart(EditPart context, Object model) {
		EditPart part = null;
		if (model instanceof SubProcessWrapper){
			if (editable){
				part = new SubProcessPart4Designer();
			}else {
				part = new BasicSubProcessPart();
			}

		}
		else if (model instanceof PoolWrapper){
			if (editable){
				part = new PoolPart4Designer();
			}else{
				part = new BasicPoolPart();
			}
			
		}
		else if (model instanceof GroupWrapper){
			if (editable){
				part = new GroupPart4Designer();
			}
			else{
				part = new BasicGroupPart();
			}
		}
		else if (model instanceof LaneWrapper){
			if (editable){
				part = new LanePart4Designer();
			}else{
				part = new BasicLanePart();
			}
			
		}
		else if (model instanceof StartNodeWrapper){
			if (editable){
				part = new StartNodePart4Designer();
			}else{
				part = new StartNodePart4Simulator();
			}
		}
		else if (model instanceof ActivityWrapper){
			if (editable){
				part = new ActivityPart4Designer();
			}else{
				part = new ActivityPart4Simulator();
			}
		}
		else if (model instanceof EndNodeWrapper){
			if (editable){
				part = new EndNodePart4Designer();
			}else{
				part = new EndNodePart4Simulator();
			}
		}		
		else if (model instanceof RouterWrapper){
			if(editable){
				part = new RouterPart4Designer();
			}else{
				part = new RouterPart4Simulator();
			}
			
		}

		else if (model instanceof TransitionWrapper){
			if (editable){
				part = new TransitionPart4Designer();
			}else{
				part = new TransitionPart4Simulator();
			}
		}
		

		if (part!=null){
			part.setModel(model);

			//((AbsWrapper)model).setEditPart(part);
		}
		return part;		
	}

}
